﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Xml;

namespace TemplateH4.admin
{
    public partial class QLGiaoDien_Banner : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));

            XmlNode root = doc.DocumentElement;
            Image1.ImageUrl = "~/admin/images/upload/" + root.SelectSingleNode("banner1").ChildNodes[0].Value;
            Label1.Text = root.SelectSingleNode("banner1").ChildNodes[0].Value;
            Image2.ImageUrl = "~/admin/images/upload/" + root.SelectSingleNode("banner2").ChildNodes[0].Value;
            Label2.Text = root.SelectSingleNode("banner2").ChildNodes[0].Value;
            Image3.ImageUrl = "~/admin/images/upload/" + root.SelectSingleNode("banner3").ChildNodes[0].Value;
            Label3.Text = root.SelectSingleNode("banner3").ChildNodes[0].Value;
            Image4.ImageUrl = "~/admin/images/upload/" + root.SelectSingleNode("banner4").ChildNodes[0].Value;
            Label4.Text = root.SelectSingleNode("banner4").ChildNodes[0].Value;

        }

        protected void btndoibanner1_Click(object sender, EventArgs e)
        {
            String filepath = bannerupload1.PostedFile.FileName;
            String filename = Path.GetFileName(filepath);
            bannerupload1.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);


            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            //XmlNode node = root.SelectSingleNode("logo").ChildNodes[0];
            XmlNode old = root.SelectSingleNode("banner1");

            XmlElement logo = doc.CreateElement("banner1");
            logo.InnerText = filename;
            root.ReplaceChild(logo, old);


            Image1.ImageUrl = "~/admin/images/upload/" + filename;

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);

        }

        protected void btndoibanner2_Click(object sender, EventArgs e)
        {
            String filepath = bannerupload2.PostedFile.FileName;
            String filename = Path.GetFileName(filepath);
            bannerupload2.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);


            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            //XmlNode node = root.SelectSingleNode("logo").ChildNodes[0];
            XmlNode old = root.SelectSingleNode("banner2");

            XmlElement logo = doc.CreateElement("banner2");
            logo.InnerText = filename;
            root.ReplaceChild(logo, old);


            Image2.ImageUrl = "~/admin/images/upload/" + filename;

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);

        }

        protected void btndoibanner3_Click(object sender, EventArgs e)
        {
            String filepath = bannerupload3.PostedFile.FileName;
            String filename = Path.GetFileName(filepath);
            bannerupload3.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);


            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            //XmlNode node = root.SelectSingleNode("logo").ChildNodes[0];
            XmlNode old = root.SelectSingleNode("banner3");

            XmlElement logo = doc.CreateElement("banner3");
            logo.InnerText = filename;
            root.ReplaceChild(logo, old);


            Image3.ImageUrl = "~/admin/images/upload/" + filename;

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);

        }

        protected void btndoibanner4_Click(object sender, EventArgs e)
        {
            String filepath = bannerupload4.PostedFile.FileName;
            String filename = Path.GetFileName(filepath);
            bannerupload4.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);


            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            //XmlNode node = root.SelectSingleNode("logo").ChildNodes[0];
            XmlNode old = root.SelectSingleNode("banner4");

            XmlElement logo = doc.CreateElement("banner4");
            logo.InnerText = filename;
            root.ReplaceChild(logo, old);


            Image4.ImageUrl = "~/admin/images/upload/" + filename;

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);
        }

        protected void btndoibanner_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            XmlNode old, logo;

            if (bannerupload1.HasFile)
            {
                String filepath = bannerupload1.PostedFile.FileName;
                String filename = Path.GetFileName(filepath);
                bannerupload1.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);
                old = root.SelectSingleNode("banner1");
                logo = doc.CreateElement("banner1");
                logo.InnerText = filename;
                root.ReplaceChild(logo, old);
                Image1.ImageUrl = "~/admin/images/upload/" + filename;
                Label1.Text = root.SelectSingleNode("banner1").ChildNodes[0].Value;
            }

            if (bannerupload2.HasFile)
            {
                String filepath = bannerupload2.PostedFile.FileName;
                String filename = Path.GetFileName(filepath);
                bannerupload2.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);
                old = root.SelectSingleNode("banner2");
                logo = doc.CreateElement("banner2");
                logo.InnerText = filename;
                root.ReplaceChild(logo, old);
                Image2.ImageUrl = "~/admin/images/upload/" + filename;
                Label2.Text = root.SelectSingleNode("banner2").ChildNodes[0].Value;
            }
            if (bannerupload3.HasFile)
            {
                String filepath = bannerupload3.PostedFile.FileName;
                String filename = Path.GetFileName(filepath);
                bannerupload3.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);
                old = root.SelectSingleNode("banner3");
                logo = doc.CreateElement("banner3");
                logo.InnerText = filename;
                root.ReplaceChild(logo, old);
                Image3.ImageUrl = "~/admin/images/upload/" + filename;
                Label3.Text = root.SelectSingleNode("banner3").ChildNodes[0].Value;
            }
            if (bannerupload4.HasFile)
            {
                String filepath = bannerupload4.PostedFile.FileName;
                String filename = Path.GetFileName(filepath);
                bannerupload4.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);
                old = root.SelectSingleNode("banner4");
                logo = doc.CreateElement("banner4");
                logo.InnerText = filename;
                root.ReplaceChild(logo, old);
                Image4.ImageUrl = "~/admin/images/upload/" + filename;
                Label4.Text = root.SelectSingleNode("banner4").ChildNodes[0].Value;
            }

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);
        }


    }
}
